define([
    'text!../fieldTemplates/Address.html',
    'text!../fieldTemplates/Checkbox.html',
    'text!../fieldTemplates/Date.html',
    'text!../fieldTemplates/Dropdown.html',
    'text!../fieldTemplates/Email.html',
    'text!../fieldTemplates/Label.html',
    'text!../fieldTemplates/Number.html',
    'text!../fieldTemplates/Paragraph.html',
    'text!../fieldTemplates/Radio.html',
    'text!../fieldTemplates/SingleLine.html',

    'text!../editTemplates/Address.html',
    'text!../editTemplates/Checkbox.html',
    'text!../editTemplates/Date.html',
    'text!../editTemplates/Dropdown.html',
    'text!../editTemplates/Email.html',
    'text!../editTemplates/Label.html',
    'text!../editTemplates/Number.html',
    'text!../editTemplates/Paragraph.html',
    'text!../editTemplates/Radio.html',
    'text!../editTemplates/SingleLine.html'
], function (Address, Checkbox, Date, Dropdown, Email, Label, Number, Paragraph, Radio, SingleLine, EditAddress,
    EditCheckbox, EditDate, EditDropdown, EditEmail, EditLabel, EditNumber, EditParagraph, EditRadio, EditSingleLine) {

        var templates = [
            {
                Name: "label2",
                DisplayName: "标题",
                Description: "",
                Placeholder: "",
                IsRequired: false,
                Size: 4,
                Column: "col-md-12",
                Template: Label,
                EditTemplate: EditLabel,
            },
            {
                Name: "single-line",
                DisplayName: "单行输入",
                Description: "",
                Placeholder: "",
                IsRequired: false,
                Size: 4,
                Column: "col-md-12",
                Template: SingleLine,
                EditTemplate: EditSingleLine
            },
            {
                Name: "number",
                DisplayName: "数字",
                Description: "",
                Placeholder: "",
                IsRequired: false,
                Size: 4,
                Column: "col-md-12",
                Template: Number,
                EditTemplate: EditNumber
                //AdditionalSettings: [{ DisplayText: "最大值", Name: "num-max", Value: "" }, { DisplayText: "最小值", Name: "mum-min", Value: "" }]
            },
            {
                Name: "email",
                DisplayName: "邮箱地址",
                Description: "",
                Placeholder: "",
                IsRequired: false,
                Size: 4,
                Column: "col-md-12",
                Template: Email,
                EditTemplate: EditEmail
            },
            {
                Name: "paragraph",
                DisplayName: "多行输入",
                Description: "",
                Placeholder: "",
                IsRequired: false,
                Size: 4,
                Column: "col-md-12",
                Template: Paragraph,
                EditTemplate: EditParagraph
            },
            {
                Name: "date",
                DisplayName: "日期",
                Description: "",
                IsRequired: false,
                Size: 4,
                Column: "col-md-12",
                Template: Date,
                EditTemplate: EditDate
            },
            {
                Name: "radio",
                DisplayName: "单项选择",
                Description: "",
                IsRequired: false,
                Size: 4,
                Column: "col-md-12",
                Template: Radio,
                EditTemplate: EditRadio,
                FieldOptions: [{ DisplayText: "选项1" }, { DisplayText: "选项2" }]
            },
            {
                Name: "dropdown",
                DisplayName: "下拉选项",
                Description: "",
                IsRequired: false,
                Size: 4,
                Column: "col-md-12",
                Template: Dropdown,
                EditTemplate: EditDropdown,
                FieldOptions: [{ DisplayText: "选项1" }, { DisplayText: "选项2" }],
            },
            {
                Name: "checkbox",
                DisplayName: "多项选择",
                Description: "",
                IsRequired: false,
                Size: 4,
                Column: "col-md-12",
                Template: Checkbox,
                EditTemplate: EditCheckbox,
                FieldOptions: [{ DisplayText: "选项1" }, { DisplayText: "选项2" }]
            },
            {
                Name: "address2",
                DisplayName: "省份地址",
                Description: "",
                IsRequired: false,
                Size: 4,
                Column: "col-md-12",
                Template: Address,
                EditTemplate: EditAddress
            }
        ];

        _.each(templates, function (template) {
            // 注册现实组件
            Vue.component(template.Name, {
                template: template.Template,
                props: {
                    field: { type: Object, default: {} },
                    actived: { type: Boolean, default: false }
                },
                model: { prop: 'field', event: 'update' },
                methods: {
                    removeField: function (field) {
                        this.$emit('remove', field);
                    }
                }
            });

            // 注册编辑组件
            Vue.component('edit-' + template.Name, {
                template: template.EditTemplate,
                props: { fieldInfo: { type: Object, default: {} } },
                model: { prop: 'fieldInfo', event: 'update' },
                methods: {
                    addOption: function (fieldOptions) {
                        this.$emit('addOption', fieldOptions);
                    },
                    removeOption: function (fieldOptions, option) {
                        this.$emit('removeOption', fieldOptions, option);
                    }
                }
            });
        });

        return templates;
    });